<!DOCTYPE html>
<html  lang="en">
    <head>
        <title>Document</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
        <link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css">   
        <script src="https://unpkg.com/swiper/swiper-bundle.min.js"> </script>
        <style>
            .swiper-container{
                width: 100%;
                height: 200px;
            }
            .swiper-slide img{
                width: 100%;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <!-- diff算法 检测到key值不同,会重新创建组件，mounted()每次都会执行 -->
            <swiper :key="datalist.length">
                <div class="swiper-slide" v-for="data in datalist">
                    {{ data }}
                </div>
            </swiper>
        </div>

        <script>
            Vue.component("swiper",
            {
                template:`
                <div class="swiper-container">
                    <div class="swiper-wrapper">
                        <slot></slot>
                    </div>

                    <div class="swiper-pagination"></div>
                </div>`,
                mounted(){
                    new Swiper ('.swiper-container',
                    {
                        autoplay: {
                            delay: 2500,
                            disableOnInteraction: false,
                        },
                        pagination: {
                            el: '.swiper-pagination',
                        }
                    })
                }
            })
            let vm = new Vue
            ({
                el: '#app',
                data: {
                    datalist: [],
                },
                mounted() {
                    setTimeout(()=>{
                        this.datalist= ["1111","22222","33333"]
                    },2000)
                },
            })
        </script>
    </body>
</html>